{* $Id$ *}
{include file="admin/lib/header.html" title="消息中心添加"}
<div class="page-header border-bottom clearfix">
  <h2 class="left">消息中心管理<span>发布消息</span></h2>
  <a href="{AnUrl('message_center/admin/index')}" class="btn btn-default btn-sm right">&lt;&nbsp;返回消息中心列表</a>
</div>
<!--start:消息中心新增-->
<div class="add-form">
  <form action="{if $is_edit}{AnUrl('message_center/admin/update')}{else}{AnUrl('message_center/admin/create')}{/if}" method="post" enctype="multipart/form-data">
    {if $is_edit}
      <input type="hidden" name="id" value="{$message['id']}">
    {/if}
    <input name="message[url]" style="width:490px;" type="hidden" class="add-f-ipt1" value="{$message['url']}" placeholder="请输入跳转的链接地址,如果不填写系统会自动生成" >
    <table class="table" cellpadding="0" cellspacing="0">
      <tr>
        <th><label for="" class="add-f-label">选择消息分类：</label></th>
        <td>
          <select class="add-f-slt1 js_type" name="message[res_name]">
            <option value="0">==请选择==</option>
            {foreach $res_name_list as $k=>$v}
                {if $k == 'notice'}
                    <option value="{$k}" {if $message['res_name'] == $k}selected{/if} >{$v}</option>
                {/if}
            {/foreach}
          </select>
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>请选择消息分类</div>
        </td>
      </tr>
      <tr {if !$message.preview_pic}style="display:none"{/if}>
        <th valign="top"><label class="add-f-label" for="">请选择图片：</label></th>
        <td class="perUpOuter">
          <div class="clearfix">
            <div class="btn-upload left">
              <a href="javascript:void(0);"><i class="icon-upload"></i>上传图片</a>
              <input type="file" class="js_upFile" name="message[preview_pic]">
            </div>
            <!-- <span class="tips left">&nbsp;&nbsp;&nbsp;图片比例：540*270</span> -->
          </div>
          <div class="js_upFileBox">
              <div class="js_upFileBox">
              {if $message.preview_pic}
              <img src="{_image($message.preview_pic, 'list')}" width="270">
              {else}
              <!-- <img src="{$smarty.const.SITE_URL}/images/m/default/focus_default.jpg" width="200"> -->
              {/if}
          </div>
          </div>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">发送给：</label></th>
        <td>
          <select class="add-f-slt1 js_type" name="push_range">
            <option value="0" {if $message['push_range'] == '0'}selected{/if} >所有人</option>
            <option value="1" {if $message['push_range'] == '1'}selected{/if} >合伙人</option>
            <option value="2" {if $message['push_range'] == '2'}selected{/if} >市场人员</option>
            <option value="3" {if $message['push_range'] == '3'}selected{/if} >合伙人和市场人员</option>
            <option value="4" {if $message['push_range'] == '4'}selected{/if} >商户端</option>
            <!-- <option value="8">个人</option> -->
          </select>
          <div class="tips"><!-- <span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>请 -->选择接收消息人(范围)</div>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">标题：</label></th>
        <td>
          <input name="message[title]" style="width:490px;" type="text" class="add-f-ipt1" value="{$message['title']}" maxlength="50" placeholder="输入消息标题,最多50个字" >
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>输入消息标题</div>
        </td>
      </tr>
      <tr>
        <th valign="top"><label class="add-f-label" for="">消息内容：</label></th>
        <td>
          <textarea class="message[content]"  name="message[content]" id="js_editor" style="width:490px;">{$message['content']}</textarea>
          <!-- <div class="tips">消息中心内容会显示在相应内容的简介位置，最多输入 <span style="color:red;">80</span> 字，还可输入 <span style="color:red;">200</span> 字</div> -->
        </td>
      </tr>
      
      <tr><th>&nbsp;</th><td class="noborder"><button type="submit" class="btn btn-success">&nbsp;&nbsp;&nbsp; {if $is_edit}重发{else}发送{/if} &nbsp;&nbsp;&nbsp;</button></td></tr>
    </table>
  </form>
</div>
<!--end:消息中心新增-->
<script>


$(function(){ 
	
	//是否创建了编辑器
	isCreateEditor = false;
	
	if ($('select[name="message[res_name]"]').val() == 'notice' ) {
        if (!isCreateEditor) {
            //初始化编辑器
            var editor = new UE.ui.Editor({
              serverUrl:"{AnUrl('core/handler/file_uploader?source=ueditor&file_field=Filedata')}",
                 initialFrameWidth:820,
                 initialFrameHeight:450,
                 elementPathEnabled:false,
                 autoHeightEnabled: false,
                 autoFloatEnabled: false,
                 wordCount: false,
                 toolbars:[['fullscreen','source', "undo","redo","justifyleft","justifycenter","justifyright","justifyjustify","lineheight","bold","italic","underline","strikethrough","fontsize","fontfamily","backcolor","forecolor","superscript","subscript","insertorderedlist","insertunorderedlist","insertimage","inserttable","emotion","spechars","unlink","link"],[]]
             });
            editor.render("js_editor");
            isCreateEditor = true;
        } else {
            /* $('div#js_editor').show();
            $('textarea').hide(); */
            isCreateEditor = false;
        }
        
    } else {
        $('div#js_editor').remove();
        $('textarea').attr('id', 'js_editor');
        $('textarea').show();
        isCreateEditor = false;
    }
	
	
	{if $is_edit}
	//初始化编辑器
    var editor = new UE.ui.Editor({
      serverUrl:"{AnUrl('core/handler/file_uploader?source=ueditor&file_field=Filedata')}",
         initialFrameWidth:820,
         initialFrameHeight:450,
         elementPathEnabled:false,
         autoHeightEnabled: false,
         autoFloatEnabled: false,
         wordCount: false,
         toolbars:[['fullscreen','source', "undo","redo","justifyleft","justifycenter","justifyright","justifyjustify","lineheight","bold","italic","underline","strikethrough","fontsize","fontfamily","backcolor","forecolor","superscript","subscript","insertorderedlist","insertunorderedlist","insertimage","inserttable","emotion","spechars","unlink","link"],[]]
     });
    editor.render("js_editor");
    isCreateEditor = true;
	{/if}
	
	
	
	//绑定分类事件
	$('select[name="message[res_name]"]').change(function(){
		if ($(this).val() == 'notice' ) {
			if (!isCreateEditor) {
				//初始化编辑器
	            var editor = new UE.ui.Editor({
	              serverUrl:"{AnUrl('core/handler/file_uploader?source=ueditor&file_field=Filedata')}",
	                 initialFrameWidth:820,
	                 initialFrameHeight:450,
	                 elementPathEnabled:false,
	                 autoHeightEnabled: false,
	                 autoFloatEnabled: false,
	                 wordCount: false,
	                 toolbars:[['fullscreen','source', "undo","redo","justifyleft","justifycenter","justifyright","justifyjustify","lineheight","bold","italic","underline","strikethrough","fontsize","fontfamily","backcolor","forecolor","superscript","subscript","insertorderedlist","insertunorderedlist","insertimage","inserttable","emotion","spechars","unlink","link"],[]]
	             });
	            editor.render("js_editor");
	            isCreateEditor = true;
			} else {
				/* $('div#js_editor').show();
	            $('textarea').hide(); */
	            isCreateEditor = false;
			}
			
		} else {
			$('div#js_editor').remove();
			$('textarea').attr('id', 'js_editor');
			$('textarea').show();
			isCreateEditor = false;
		}
	});
	
	
	
	
  // 提交验证
  $('form').submit(function(){
    //验证
    if($('select[name="message[res_name]"]').val() == '0' || !$('select[name="message[res_name]"]')){
      showMsg('请选择消息分类!');
      return false;
    };
    if($('input[name="message[title]"]').val() == '' || !$('input[name="message[title]"]').val()){
      showMsg('消息标题不能为空!');
      return false;
    };
    
    if($('select[name="message[res_name]"]').val() == 'notice' && $('textarea').val() == ''){
    	showMsg('公告内容不能为空!');
    }
    
  });

  /* $('.js_type').change(function(){
    if ($(this).val() == 'event') {
      $(this).parents('tr').next().slideDown();
    } else {
      $(this).parents('tr').next().slideUp();
      $(this).parents('tr').next().find('input').val('');
    }
  }); */

  /* // 上传图片预览
  $(".js_upFile").each(function(i){
    $(this).change(function(e){
      handleFileSelect($(this), 270);
    });
  }); */
});

</script>
{include_core file="admin/lib/footer.html"}